package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.RelationDefineDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RelationDefineMapper {
    
    @Select("SELECT * FROM relation_define WHERE id = #{id}")
    RelationDefineDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM relation_define WHERE semantic_network_id = #{semanticNetworkId}")
    List<RelationDefineDO> findBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Insert("INSERT INTO relation_define(name, semantic_network_id, parameter_list, create_time, update_time) " +
            "VALUES(#{name}, #{semanticNetworkId}, #{parameterList}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(RelationDefineDO relationDefineDO);
    
    @Update("UPDATE relation_define SET name = #{name}, semantic_network_id = #{semanticNetworkId}, " +
            "parameter_list = #{parameterList}, update_time = NOW() WHERE id = #{id}")
    int update(RelationDefineDO relationDefineDO);
    
    @Delete("DELETE FROM relation_define WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
    
    @Delete("DELETE FROM relation_define WHERE semantic_network_id = #{semanticNetworkId}")
    int deleteBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
} 